//index.js
//获取应用实例
const app = getApp()
const Api = require("../../utils/api.js").API
// const Store = require("../../utils/store.js").store
const codeZ = require("../../utils/util.js")
Page({
    data: {
        active:0,
        Serchvalue:'',
        tabsArray: [{
                "completeStatus": "商 品",
                "list": [],
                "total": 0
            },
            {
                "completeStatus": "发 现",
                "list": [],
                "total": 0
            },
            
            
            
        ],
        hei2:400,
        type:'109601',
        userStatus:'',
     
    },
    onShow(){
        let baseinfo =  wx.getStorageSync('baseInfo');
           if(baseinfo.hasOwnProperty('ckType')){
               this.setData({
                   userStatus:baseinfo.ckType
               })
           }else{
               this.setData({
                   userStatus:''
               })
           }
           
        this.setData({
            
             hei2:app.globalData.screenHeight-120,
             
        })
         this.requstList(this.data.type,1);
    },
    onSerach(e) {
        console.log(e);
       
        this.setData({
            Serchvalue: e.detail
        })
    },
    onSureSearch:function(){
        this.requstList(this.data.type,1);
    },
    
   
    // clickHome:function(){
    //     wx.switchTab({
    //         url:'../GoodsList/index'
    //     })
    // },
    goShop:function(e){
          let i = e.currentTarget.dataset.item;
      
    
        wx.navigateTo({
                 url: '../../pages/shouliren/index',
                   success: function(res) {
                     // 通过eventChannel向被打开页面传送数据
                     res.eventChannel.emit('acceptDataFromOpenerPage', { data:i })
                   }
           })
             
     
        
     },
     clickJump:function(e){
         let i = e.currentTarget.dataset.item['evNo'];   
          if(i == null){
              return
          }
         wx.navigateTo({
                 url: '../DetailData/index',
                    success: function(res) {
                      // 通过eventChannel向被打开页面传送数据
                      res.eventChannel.emit('acceptDataFromOpenerPage', { data:i })
                    }
            })    
     },
    onChange:function(e){
        let a = e.detail.index;
        if(a == 0){
            this.setData({
                type:'109601',
                page:1
            })
        }else{
            this.setData({
                type:'109602',
                 page:1
            })
        }
        this.requstList(this.data.type,1);
        // console.log(e);
    },
    requstList:function(type,page){
      
       let that = this;
       if(page == 1){
           this.setData({
               list:[],
           })
       }
       
       
      var  data={
                   	"asc": true,
                   	"busiType": type,
                   	"limit": 10,
                   	"name": this.data.Serchvalue,
                   	"page": page,
                   	"sidx": ""                                 
                  } 
                  
        if(type == '109601'){
     
        Api.cheakSCApi(data).then(res=>{
            console.log(res);
            if(res.code == 0){
                var arr =  res.page.records;           
                 
                  if (arr.length == 0) {
                      return;
                  }
              
                var oldArr = that.data.list;
                             
                var newArr = oldArr.concat(arr); 
              
                that.setData({
                    list:newArr,
                    total:res.page.total,
                    
                })   
            }else if(res.code == "401"){
                that.setData({
                    isShow:true,    
                })   
                
            }else{
                
            }
        
        })
    
    }else{
       
         Api.evlistApi(data).then(res=>{
             console.log(res);
             if(res.code == 0){
                 var arr =  res.page.records;           
                  
                   if (arr.length == 0) {
                       return;
                   }
                   arr.forEach(item=>{
                       item.evFile = JSON.parse(item.evFile);
                   })
               
                 var oldArr = that.data.list;
                              
                 var newArr = oldArr.concat(arr); 
               
                 that.setData({
                     list:newArr,
                     total:res.page.total,
                     
                 })   
             }else if(res.code == "401"){
                 that.setData({
                     isShow:true,    
                 })   
                 
             }else{
                 
             }
         
         })
             
    }
    },

    refreshBottom:function(e){
         //  var i = e.currentTarget.dataset.index;
         // // let list = `tabsArray[${i}].list`;
         
       
          var total = this.data.total;
          var list = this.data.list;
              
          if(list.length <total){
              var a = this.data.page;     
              a++;
              this.setData({
                  page: a
              }) 
               this.requstList(this.data.type,a)
              
          }
                    
        
    }
    
    
    
  
  

  







});
